import 'package:chop/widgets/TextSizeWidget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class LoadingDialog extends Dialog {
  String text;

  LoadingDialog({Key key, @required this.text}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Material(
          //创建透明层
          type: MaterialType.transparency, //透明类型
          child: Center(
            //保证控件居中效果
            child: SizedBox(
              width: 120,
              height: 120,
              child: Container(
                decoration: ShapeDecoration(
                  color: Colors.white,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(8),
                    ),
                  ),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    CircularProgressIndicator(),
                    Padding(
                      padding: EdgeInsets.only(
                        top: 20,
                      ),
                      child: FixedSizeText(
                        text,
                        style: TextStyle(fontSize: 12),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
        onWillPop: () async => false);
  }
}

class AlertDia extends Dialog {
  String text;
  VoidCallback yes;
  VoidCallback no;
  AlertDia({Key key, @required this.text, this.yes, this.no}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Material(
          //创建透明层
          type: MaterialType.transparency, //透明类型
          child: Center(
            //保证控件居中效果
            child: SizedBox(
              width: 200,
              height: 100,
              child: Container(
                decoration: ShapeDecoration(
                  color: Colors.white,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(
                      Radius.circular(8),
                    ),
                  ),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
//                    CircularProgressIndicator(),
                    Padding(
                      padding: EdgeInsets.only(left: 15,top: 20, right: 15),
                      child: FixedSizeText("确认${text}吗？"),
                    ),
                    Container(height: 14,),
                    Row(
                      children: <Widget>[
                        Expanded(
//                          flex: 5,
                          child: RaisedButton(
                            child: FixedSizeText("取消"),
                            color: Color.fromRGBO(255, 255, 255, 0.99),
                            padding: EdgeInsets.only(top: 10,bottom: 10),
                            elevation:0.0,
//                            textColor: Colors.black26,
//                            shape: RoundedRectangleBorder(
//                              borderRadius: BorderRadius.circular(10),
//                            ),
                            onPressed: no,
                          ),
                        ),
                        Expanded(
//                          flex: 5,
                          child: RaisedButton(
                            child: FixedSizeText("${text}"),
                            elevation:0.0,
                            color: Color.fromRGBO(255, 255, 255, 0.99),
                            padding: EdgeInsets.only(top: 10,bottom: 10),
                            textColor: Colors.redAccent,
//                            shape: RoundedRectangleBorder(
//                              borderRadius: BorderRadius.circular(10),
//                            ),
                            onPressed: yes,
                          ),
                        )
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        ),
        onWillPop: () async => false);
  }
}
class showDia extends Dialog {
  Widget child;
  String text;
  showDia({Key key, @required this.text, @required this.child}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: GestureDetector(
            onTap: (){
              print("点击了背景");
              Get.back();
            },
            child:Material(
          //创建透明层
          type: MaterialType.transparency, //透明类型
          child:  Center(
              //保证控件居中效果
              child: GestureDetector(
                onTap: (){
                  print("点击了Center");
                },
                child: SizedBox(
                  width: 200,
                  height: 100,
                  child: Container(
                    decoration: ShapeDecoration(
                      color: Colors.white,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(
                          Radius.circular(8),
                        ),
                      ),
                    ),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        FixedSizeText(text),
                        Padding(
                          padding: EdgeInsets.only(left: 15,top: 10, right: 15),
                          child: child,
                        ),
                        Container(height: 14,),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          )
        ),
        onWillPop: () async => false);
  }
}
